package Offer009;

/**
 * . 乘积小于 K 的子数组
 * @author 23737
 * @time 2021.12.6
 */
public class Test {
    public static void main(String[] args) {

    }
}

/**
 * 滑动窗口
 */
class Solution {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        int n = nums.length;
        if(n == 0){
            return 0;
        }
        int res =  0;
        int start = 0;
        int end = 0;
        int product = 1;
        while(end < n){
            //但是这里要注意 end++  不能放在while循环的最后
            product *= nums[end++];
            while(product >= k && end > start){
                product /= nums[start++];
            }
            if(end > start){
                res += end- start;
            }
        }
        return res;
    }
}
